/*
 * @Author: sdq 483657864@qq.com
 * @Date: 2025-04-17 16:27:21
 * @LastEditors: sdq 483657864@qq.com
 * @LastEditTime: 2025-04-19 13:38:58
 * @FilePath: \ranyu_anchor_new\src\agroa\auxiliary\index.ts
 * @Description: 辅助方法
 */
/**
 * 重置所有状态至初始值
 */
export const resetState = async () => {
  const { useLiveStatusStore } = await import("@/store");
  const { useRemoteStore } = await import("@/store");
  const { useAudioStore } = await import("@/store");
  const liveStatus = useLiveStatusStore();
  const remoteStore = useRemoteStore();
  const audioStore = useAudioStore();
  liveStatus.$reset();
  remoteStore.$reset();
  audioStore.$reset();
  // liveStatus.changeJoinStatus(false);
  // liveStatus.changeSpeakingStatus(false);
  // liveStatus.changenetworkQuality(0);
  // remoteStore.updateActiveSpeakers([]);
  // audioStore.setMic(undefined);
  // audioStore.setSystem(undefined);
};
/**
 * 统一错误处理
 * @param msg - 错误前缀信息
 * @param error - 原始错误对象
 */
export const handleError = (msg: string, error: unknown) => {
  const err = error as Error;
  ElMessage.error(`${msg}: ${err.message || "未知错误"}`);
  console.error(`[Error] ${msg}:`, error);
};

/** 用于取消未完成的异步操作 */
let abortController = new AbortController();
/** 清理未完成的异步操作并重置控制器 */
export const cleanup = () => {
  abortController.abort();
  abortController = new AbortController();
};
